package distributedbank;

import distributedbank.client.ClientUI;
import distributedbank.server.BankBranch;

/**
 * Main Class
 */
public class DistributedBank
{
    /**
     * Main function entry
     * 
     * @param args
     *            [0]: JVM number. 1-4: bank branch 5-8: clientUI
     */
    public static void main( String[] args ) {
        if( args.length != 1 ) {
            throw new IllegalArgumentException(
                    "Bank components must be passed a "
                            + "branch # argument to run" );
        } else {
            int paramId;
            try {
                paramId = Integer.parseInt( args[0] );
            } catch( java.lang.NumberFormatException nfe ) {
                System.out.println( "Parameter Error!" );
                return;
            }
            // jvm 1 - 12 are for servers
            if( paramId < 13 ) {
                BankBranch branch = new BankBranch( paramId );
                branch.runServer();
            } else {
                // jvm 13 - 16 are for clients
                new ClientUI( paramId );
            }
        }
    }
}
